#include "Camera.h"


Camera::Camera(int _left,int _right,int _bottom)
{	
	
	left = _left;
	right = _right - CENTER_H;	
	vp_y = top = TOP;
	bottom = _bottom - CENTER_V;
	if(bottom < 480) bottom = TOP;
	D3DXMatrixIdentity(&this->matrixI4);
	matrixI4._22 = -1;
}


Camera::~Camera(void)
{
}

void Camera::update(D3DXVECTOR2 target)
{	
	if(target.x < right)
	{
		vp_x = target.x - CENTER_H;
		if(vp_x < left) vp_x = left;

		if(target.x > left + CENTER_H)
		{		
			left = vp_x;
		}
	}
	if(top < bottom)
	{
		vp_y = target.y + CENTER_V;
		if(vp_y < top) vp_y = top;

		if(vp_y > top)
		{		
			top = vp_y ;
		}
	}
	

}

D3DXMATRIX* Camera::getTransformedMatrix()
{
	D3DXMATRIX transfromMatrix;
	D3DXMatrixTranslation(&transfromMatrix,-vp_x,vp_y,0);
	//nhan nguoc
	D3DXMatrixMultiply(&this->transform,&matrixI4,&transfromMatrix);
	return &transform;

}

float Camera::getLeftSide()
{
	return left;
}

float Camera::getRightSide()
{
	return left + LOOK;
}
